<?php

/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: debug.inc.php 4867 2010-11-10 07:12:14Z yexinhao $
 */

if(!defined('IN_BRAND')) {
	exit('Access Denied');
}

if(D_BUG) {
echo '
<!--
***************************** debug *********************************************
-->
<hr>
<script src="http://www.laabc.com/apps/float/js/float.js" type="text/javascript"></script>
<!-- link href="http://www.laabc.com/apps/float/css/base.css" rel="stylesheet" type="text/css" / -->
<!-- link href="http://www.laabc.com/apps/float/css/demo.css" rel="stylesheet" type="text/css" / -->
<iframe id="__debug_action_frame" name="__debug_action_frame" src="" style="display:none;"></iframe>
<div id="__debug_action_div" name="__debug_action_div" src="" style="display:none;"></div>
<div class="add-rss-to clearfix">
	<div class="title l" style="float:left;">T</div>
	<div class="float-box-content l" style="float:left;">
	<ul>';
if ($_G['role'] == "admin") {
	echo '<li><a target="_blank" href="admin.php"> Admin </a></li>';
	echo '

		<li>-------------</li>
		<li><a onclick="return __debug_chage_sitetheme(\'default\');" href="javascript:;"> [Site] Default Theme </a></li>
		<li><a onclick="return __debug_chage_sitetheme(\'blue\');" href="javascript:;"> [Site] Bule Theme </a></li>
	';
} elseif ($_G['role'] == "manager") {
	echo '<li><a target="_blank" href="panel.php"> Panel </a></li>';
}


if (CURSCRIPT == 'shop') {
	echo '<li>-------------</li>';
echo '
		<li><a target="__action_frame" onclick="return __debug_chage(this);return false;" href="admin.php?action=theme&amp;itemid=' . $_G['shopid'] . '&amp;op=usetheme&amp;theme=default"> [Shop] Default Theme </a></li>
		<li><a target="__action_frame" onclick="return __debug_chage(this);return false;" href="admin.php?action=theme&amp;itemid=' . $_G['shopid'] . '&amp;op=usetheme&amp;theme=t1"> [Shop] Bule Theme </a></li>
';
}
echo '	</ul>
	</div>
</div>
<script type="text/javascript">
function __debug_chage_sitetheme(sitetheme) {
	$.post("admin.php?action=ads&inajax=1", {formhash:"' . $_G['formhash'] . '", sitetheme:sitetheme, valuesubmit:"yes", inajax:"1", inframe:"no"}, function (data, textStatus){
		//alert(typeof(data));
		//if (msg == null) {
		//alert("You are not login or second login !");
		//}
		location.reload();
	});
}
function __debug_chage(obj) {
	$.get(obj.href, {inajax:"1", inframe:"no"}, function (data, textStatus){
		location.reload();
	});

	return false;
}

$(".add-rss-to").float({
					   position:"rm",
					   offset : {right : -153},
					   style:{width:180}
					  });
$(".add-rss-to").hover(function(){
	$(this).float("clearOffset","fast");
},function(){
	$(this).float("addOffset");
})

</script>
<style>

.float-box{border:1px solid #FF9;background-color:#FFC;width:140px;height:100px;padding:10px;}


.add-rss-to,add-collect-to{
	z-index:10000;
	overflow:hidden;
}
.add-rss-to .title,.add-collect-to .title{
	background-color:#29567D;
	width:27px;height:65px;
	color:#FFF;font-size:14px;font-weight:bold;text-align:center;
	padding-top:20px;
	cursor:pointer;
}
.add-collect-to .title{
	float:right;
}

.float-box-content{
	border:2px solid #A0AFC3;
	background-color:#ECF4FC;
}
.float-box-content ul{
	margin:10px;
}
.float-box-content ul li{
	padding:2px 0px;
}


<style>


<style>
.tclass, .tclass2 {
text-align:left;width:760px;border:0;border-collapse:collapse;margin-bottom:5px;table-layout: fixed; word-wrap: break-word;background:#FFF;}
.tclass table, .tclass2 table {width:100%;border:0;table-layout: fixed; word-wrap: break-word;}
.tclass table td, .tclass2 table td {border-bottom:0;border-right:0;border-color: #ADADAD;}
.tclass th, .tclass2 th {border:1px solid #000;background:#CCC;padding: 2px;font-family: Courier New, Arial;font-size: 11px;}
.tclass td, .tclass2 td {border:1px solid #000;background:#FFFCCC;padding: 2px;font-family: Courier New, Arial;font-size: 11px;}
.tclass2 th {background:#D5EAEA;}
.tclass2 td {background:#FFFFFF;}
.firsttr td {border-top:0;}
.firsttd {border-left:none !important;}
.bold {font-weight:bold;}
</style>
';
	$class = 'tclass2';
	if(empty($_SGLOBAL['debug_query'])) $_SGLOBAL['debug_query'] = array();

	foreach ($_SGLOBAL['debug_query'] as $dkey => $debug) {
		($class == 'tclass')?$class = 'tclass2':$class = 'tclass';
		$str = '';
		$str .= '<table cellspacing="0" class="'.$class.'"><tr><th rowspan="2" width="20">'.($dkey+1).'</th><td width="60">'.$debug['time'].' ms</td><td class="bold">'.shtmlspecialchars($debug['sql']).'</td></tr>';
		if(!empty($debug['info'])) {
			$str .= '<tr><td>Info</th><td>'.$debug['info'].'</td></tr>';
		}
		if(!empty($debug['explain'])) {
			$str .=  '<tr><td>Explain</td><td><table cellspacing="0"><tr class="firsttr"><td width="5%" class="firsttd">id</td><td width="10%">select_type</td><td width="12%">table</td><td width="5%">type</td><td width="20%">possible_keys</td><td width="10%">key</td><td width="8%">key_len</td><td width="5%">ref</td><td width="5%">rows</td><td width="20%">Extra</td></tr><tr>';
			foreach ($debug['explain'] as $ekey => $explain) {
				($ekey == 'id')?$tdclass = ' class="firsttd"':$tdclass='';
				if(empty($explain)) $explain = '-';
				$str .= '<td'.$tdclass.'>'.$explain.'</td>';
			}
			$str .= '</tr></table></td></tr>';
		}
		$str .= '</table>';
		//慢查询日志
		if(defined('SLOWTIME') && $debug['time']>SLOWTIME) {
			@$fp = fopen(B_ROOT.'./data/log/slowquery.html.php', 'a');
			@flock($fp, 2);
			@fwrite($fp, "<?exit?><pre>$_G[timestamp]\t$_G[uid]\t$_SGLOBAL[onlineip]\t$_SERVER[REQUEST_URI]\t$_SERVER[QUERY_STRING]</pre>\n$str");
			@fclose($fp);
		}
		echo $str;
	}

	if($files = get_included_files()) {
		($class == 'tclass')?$class = 'tclass2':$class = 'tclass';
		echo '<table class="'.$class.'">';
			foreach ($files as $fkey => $file) {
				echo '<tr><th width="20">'.($fkey+1).'</th><td>'.$file.'</td></tr>';
			}
		echo '</table>';
	}

	if($cookies = $_COOKIE) {
		($class == 'tclass')?$class = 'tclass2':$class = 'tclass';
		$i = 1;
		echo '<table class="'.$class.'">';
			foreach ($cookies as $ckey => $cookie) {
				echo '<tr><th width="20">'.$i.'</th><td width="250">$_COOKIE[\''.$ckey.'\']</td><td>'.$cookie.'</td></tr>';
				$i++;
			}
		echo '</table>';
	}
	if(0 && $server = $_SERVER) {
		($class == 'tclass')?$class = 'tclass2':$class = 'tclass';
		$i = 1;
		echo '<table class="'.$class.'">';
			foreach ($server as $ckey => $value) {
				echo '<tr><th width="20">'.$i.'</th><td width="250">$_SERVER[\''.$ckey.'\']</td><td>'.$value.'</td></tr>';
				$i++;
			}
		echo '</table>';
	}
	if($values = $_REQUEST) {
		($class == 'tclass')?$class = 'tclass2':$class = 'tclass';
		$i = 1;
		echo '<table class="'.$class.'">';
			foreach ($values as $ckey => $value) {
				echo '<tr><th width="20">'.$i.'</th><td width="250">$_REQUEST[\''.$ckey.'\']</td><td>'.$value.'</td></tr>';
				$i++;
			}
		echo '</table>';
	}
}

?>